<!-- 申请支付 -->
<template>
  <el-dialog title="申请付款" :visible.sync="visible" width="60%">
    <el-form
      :model="formModel"
      label-width="130px"
      :rules="rules"
      ref="formModel"
      size="mini"
    >
      <template>
        <el-card>
          <el-col :span="12">
            <el-form-item label="供应商名称" prop="contractId">
              {{ "字段数据" }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商ID" prop="contractId">
              {{ "字段数据" }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账单结算金额" prop="contractId">
              {{ "字段数据" }}
            </el-form-item>
          </el-col>
        </el-card>
        <el-card>
          <el-col :span="12">
            <el-form-item label="申请付款金额" prop="num">
              <el-input
                placeholder="请输入"
                style="width: 550px"
                v-model="formModel.num"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="OA审批单ID" prop="num">
              <el-input
                placeholder="请输入"
                style="width: 550px"
                v-model="formModel.num"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="申请付款方式" prop="num">
              <el-radio-group v-model="formModel.resource">
                <el-radio label="现金"></el-radio>
                <el-radio label="抵顶物"></el-radio>
                <el-radio label="现金+抵顶物"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="" prop="num">
              <el-input
                placeholder="请输入"
                style="width: 550px"
                v-model="formModel.num"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="付款时间" prop="repairTime" clearable>
              <el-date-picker
                placeholder="请选择"
                type="datetimerange"
                range-separator="~"
                style="width: 340px"
                value-format="yyyy-MM-dd HH:mm:ss"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item label="付款备注" prop="num">
              <el-input
                placeholder="请输入"
                style="width: 550px"
                v-model="formModel.num"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="上传发票附件" prop="offsetAgreement">
              <file-upload
                :isShowTip="false"
                v-model="formModel.offsetAgreement"
                :fileType="['png', 'jpg', 'jpeg']"
              ></file-upload>
            </el-form-item>
          </el-col>
        </el-card>
      </template>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handelCancel">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
    
    <script>
import SelectNameDialog from "@/components/SelectDialog/SelectNameDialog";
//
import {
  addOrders,
  updateOrders,
  getOrders,
  allInventory,
} from "@/api/service/orderCenter/purchase";
import { validatePhoneNumber } from "@/utils";

export default {
  components: {
    SelectNameDialog,
  },
  data() {
    return {
      originList: [
        {
          orderId1: "sdsa",
          orderId2: "231vdxs",
          orderId3: "fdsaad22csfd",
          orderId4: "w231ds",
        },
      ],
      visible: false,
      selectFirmVisible: false,
      rules: {
        nickName: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "change",
          },
        ],
        deliveryType: [
          {
            required: true,
            message: "请选择配送方式",
            trigger: "change",
          },
        ],
        num: [
          {
            required: true,
            message: "请输入订货数量",
            trigger: "change",
          },
        ],
        orgId: [
          {
            required: true,
            message: "请选择机构",
            trigger: "change",
          },
        ],
        deptId: [
          {
            required: true,
            message: "请选择部门",
            trigger: "change",
          },
        ],
        phonenumber: validatePhoneNumber(),
        rawMaterialId: [
          {
            required: true,
            message: "请选择原料",
            trigger: "change",
          },
        ],
        unloadInventoryId: [
          {
            required: true,
            message: "请选择卸货仓库",
            trigger: "change",
          },
        ],
        capacity: [
          {
            required: true,
            message: "请输入仓库容量",
            trigger: "change",
          },
        ],
        province: [
          {
            required: true,
            message: "请选择",
            trigger: "change",
          },
        ],
        city: [
          {
            required: true,
            message: "请选择",
            trigger: "change",
          },
        ],
        county: [
          {
            required: true,
            message: "请选择",
            trigger: "change",
          },
        ],
        location: [
          {
            required: true,
            message: "请输入详细地址",
            trigger: "change",
          },
        ],
        location: [
          {
            required: true,
            message: "请输入详细地址",
            trigger: "change",
          },
        ],
        supplierId: [
          {
            required: true,
            message: "请选择供应商",
            trigger: "change",
          },
        ],
        carriersId: [
          {
            required: true,
            message: "请选择承运商",
            trigger: "change",
          },
        ],
      },
      formModel: {
        rawMaterialId: "",
        deliveryType: "",
        num: "",
        capacity: "",
        province: "",
        city: "",
        county: "",
        location: "",
      },
      total: 0,
      allInve: [],
      initObj: {},
    };
  },
  methods: {
    getList(val) {
      console.log(val);
    },
    // 取消
    handelCancel() {
      this.$refs.formModel.resetFields();
      this.visible = false;
    },
    handleSubmit() {
      this.$refs.formModel.validate((valid) => {
        if (valid) {
          this.handleValidateSuccess();
        } else {
          return false;
        }
      });
    },
    // 初始化函数--->父级调用
    handelInit(val) {
      this.initObj = val;
      this.visible = true;
    },
    getAllInventory() {
      allInventory().then((res) => {
        this.allInve = res.data.map((item) => ({
          ...item,
          label: item.name,
          value: item.id,
        }));
      });
    },
    handleValidateSuccess() {
      return;
      if (!this.userId) {
        addOrders({
          ...this.formModel,
        }).then((res) => {
          console.log(res);
          this.handelCancel();
        });
      } else {
        updateOrders({
          ...this.formModel,
        }).then((res) => {
          console.log(res);
          this.handelCancel();
        });
      }
    },
    handleBack() {
      this.$router.push({
        path: "/orderCenter/purchase/index",
      });
    },
    selectFirm(row) {
      this.form.contractId = row.id;
      this.form.subjectFirmName = row.name;
      this.$refs.form.validateField("contractId");
    },
    getUserInfo(userId) {
      if (userId) {
        getOrders(userId).then((response) => {
          console.log("11123", response);
          this.formModel = {
            ...this.formModel,
            ...response.data,
            ...response.sysUserInfo,
          };
        });
      }
    },
  },
  created() {
    this.getAllInventory();
    this.userId = this.$route.query.id;
    if (this.userId) {
      this.getUserInfo(this.userId);
    }
  },
  computed: {
    title() {
      return !this.$route?.query?.id ? "新增采购订单" : "修改采购订单";
    },
  },
};
</script>
    
    <style lang="scss" scoped>
.tree-border {
  width: 150px;
}
.place_container {
  display: flex;
  .el-form-item {
    margin-right: 10px;
    margin-bottom: 5px;
  }
}
.el-form-item {
  margin-bottom: 9px;
}
.hui {
  ::v-deep.el-card__body {
    padding-bottom: 0;
  }
}
</style>
    